import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _dec2, _class, _class2;

import React from 'react';
import { Form, Input, Modal } from 'antd';
import { Bind } from 'lodash-decorators';
import uuid from 'uuid/v4';
import intl from 'utils/intl';
var FormItem = Form.Item;
var formLayout = {
  labelCol: {
    span: 4
  },
  wrapperCol: {
    span: 18
  }
};
var ItemForm = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_React$PureComponent) {
  _inherits(ItemForm, _React$PureComponent);

  var _super = _createSuper(ItemForm);

  function ItemForm() {
    _classCallCheck(this, ItemForm);

    return _super.apply(this, arguments);
  }

  _createClass(ItemForm, [{
    key: "handleOk",
    value: function handleOk() {
      var _this$props = this.props,
          form = _this$props.form,
          _this$props$onOk = _this$props.onOk,
          onOk = _this$props$onOk === void 0 ? function (e) {
        return e;
      } : _this$props$onOk,
          _this$props$initData = _this$props.initData,
          initData = _this$props$initData === void 0 ? {} : _this$props$initData;
      form.validateFields(function (err, fieldsValue) {
        if (!err) {
          var data = initData.propertyId !== undefined ? _objectSpread(_objectSpread({}, initData), fieldsValue) : _objectSpread(_objectSpread({}, fieldsValue), {}, {
            propertyId: uuid(),
            isCreate: true
          });
          onOk(data);
        }
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          form = _this$props2.form,
          initData = _this$props2.initData,
          title = _this$props2.title,
          modalVisible = _this$props2.modalVisible,
          onCancel = _this$props2.onCancel;
      var getFieldDecorator = form.getFieldDecorator;
      var propertyCode = initData.propertyCode,
          propertyValue = initData.propertyValue;
      return /*#__PURE__*/React.createElement(Modal, {
        destroyOnClose: true,
        title: title,
        visible: modalVisible,
        onCancel: onCancel,
        onOk: this.handleOk
      }, /*#__PURE__*/React.createElement(Form, null, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        label: intl.get('cmsg.email.model.email.propertyCode').d('属性编码')
      }), getFieldDecorator('propertyCode', {
        initialValue: propertyCode,
        rules: [{
          type: 'string',
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cmsg.email.model.email.propertyCode').d('属性编码')
          })
        }]
      })( /*#__PURE__*/React.createElement(Input, {
        trim: true,
        inputChinese: false
      }))), /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        label: intl.get('cmsg.email.model.email.propertyValue').d('属性值')
      }), getFieldDecorator('propertyValue', {
        initialValue: propertyValue,
        rules: [{
          type: 'string',
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cmsg.email.model.email.propertyValue').d('属性值')
          })
        }]
      })( /*#__PURE__*/React.createElement(Input, null)))));
    }
  }]);

  return ItemForm;
}(React.PureComponent), (_applyDecoratedDescriptor(_class2.prototype, "handleOk", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "handleOk"), _class2.prototype)), _class2)) || _class);
export { ItemForm as default };